import React, { useRef, useState } from "react";
//导入 PubSub
import PubSub from 'pubsub-js';

export default function Search() {
  //创建 ref 容器
  let input = useRef();
  //声明 search 函数, 完成点击搜索功能 {a: 100, b: 200}
  let search = async () => {
    //获取 input 框输入的内容
    // console.log(input.current.value);
    //发布消息
    PubSub.publish('keyword', input.current.value)
  };

  return (
    <div className="hero-search">
      <input type="text" ref={input} /> <button onClick={search}>搜索</button>
    </div>
  );
}
